home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / JAVANMI.ZIP / LittleWalk / LittleWalk.java < prev    next >
Text File  |  1997-01-09  |  3KB  |  130 lines

  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.util.*;
  4. import LittleWalkFrame;
  5. import ProcessEntry32;
  6. import ToolHelp;
  7.  
  8. public class LittleWalk extends Applet implements Runnable
  9. {
  10.     Thread     m_LittleWalk = null;
  11.     ToolHelp th;
  12.     List ProcList;
  13.  
  14.     // STANDALONE APPLICATION SUPPORT:
  15.     //        m_fStandAlone will be set to true if applet is run standalone
  16.     //--------------------------------------------------------------------------
  17.     boolean m_fStandAlone = false;
  18.  
  19.     public static void main(String args[])
  20.     {
  21.         
  22.         Frame frame = new Frame("LittleWalk");
  23.  
  24.         // Must show Frame before we size it so insets() will return valid values
  25.         //----------------------------------------------------------------------
  26.         frame.show();
  27.         frame.hide();
  28.         frame.resize(frame.insets().left + frame.insets().right  + 320,
  29.                      frame.insets().top  + frame.insets().bottom + 240);
  30.  
  31.         LittleWalk applet_LittleWalk = new LittleWalk();
  32.  
  33.         frame.add("Center", applet_LittleWalk);
  34.         applet_LittleWalk.m_fStandAlone = true;
  35.         applet_LittleWalk.init();
  36.         applet_LittleWalk.start();
  37.         frame.show();
  38.     }
  39.  
  40.     public LittleWalk()
  41.     {
  42.     }
  43.  
  44.     public String getAppletInfo()
  45.     {
  46.         return "Name: LittleWalk\r\n" +
  47.                "Author: Andy Wilson\r\n" +
  48.                "Created with Microsoft Visual J++ Version 1.0";
  49.     }
  50.  
  51.  
  52.     public void init()
  53.     {
  54.         
  55.         // If you use a ResourceWizard-generated "control creator" class to
  56.         // arrange controls in your applet, you may want to call its
  57.         // CreateControls() method from within this method. Remove the following
  58.         // call to resize() before adding the call to CreateControls();
  59.         // CreateControls() does its own resizing.
  60.         //----------------------------------------------------------------------
  61.  
  62.         resize(320, 240);
  63.         
  64.         setLayout(new BorderLayout());
  65.         add("North", ProcList = new List());
  66.  
  67.     }
  68.  
  69.     public void destroy()
  70.     {
  71.     }
  72.  
  73.     public void paint(Graphics g)
  74.     {
  75.         g.drawString("Running: " + Math.random(), 10, 20);
  76.     }
  77.  
  78.     public void start()
  79.     {
  80.         if (m_LittleWalk == null)
  81.         {
  82.             m_LittleWalk = new Thread(this);
  83.             m_LittleWalk.start();
  84.         }
  85.     }
  86.     
  87.     public void stop()
  88.     {
  89.         if (m_LittleWalk != null)
  90.         {
  91.             m_LittleWalk.stop();
  92.             m_LittleWalk = null;
  93.         }
  94.     }
  95.  
  96.     public void run()
  97.     {
  98.         th = new ToolHelp();
  99.         Vector foo = th.getProcList();
  100.  
  101.         ProcessEntry32 temp = null;
  102.         while(foo.size () > 0)
  103.         {
  104.             try
  105.             {
  106.                 temp = (ProcessEntry32) foo.firstElement();
  107.                 ProcList.addItem("PE32="+temp.szExeFile+" "+temp.cntThreads);
  108.                 foo.removeElement( temp);
  109.             } catch (NoSuchElementException ne)
  110.             {
  111.                 System.out.println(ne.getMessage());
  112.             }
  113.         }
  114.         while (true)
  115.         {
  116.             try
  117.             {
  118.                 repaint();
  119.                 Thread.sleep(50);
  120.             }
  121.             catch (InterruptedException e)
  122.             {
  123.                 stop();
  124.             }
  125.         }
  126.     }
  127.  
  128.  
  129. }
  130.